// pages/calendar/index.js
var app = getApp();
//var activity_js = require('../../utils/activity.js');
var calendar_js = require('../../utils/calendar.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    calendar_list: [],
    rightArrow: "../../../image/mine-menu/right-arrow.png",
    nav: ["我发布的", "组织发布", "我关注的"],
    currentTab: 0,
    activity_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var currentTab = that.data.currentTab;
    calendar_js.my_calendar_list(function (res){
      console.log(res);
      if (res.data.op == 'my_calendar_list') {
        var my_calendar_list = res.data.data;
        that.setData({
          my_calendar_list: my_calendar_list,
        });
      }
      that.refresh_calendar_list_view();
    });

  },
  navtap: function (e) {
    var that = this;
    console.log(e);
    var currentTab = e.target.dataset.id;
    this.setData({
      currentTab: currentTab,
    })
    that.refresh_calendar_list_view();
    //that.refresh_activity_list();
  },
  refresh_calendar_list_view: function () {
    var that = this;
    switch (that.data.currentTab) {
      case 0:
        var calendar_list = that.data.my_calendar_list.my_created_list;
        break;
      case 1:
        var calendar_list = that.data.my_calendar_list.my_org_created_list;
        break;
      case 2:
        var calendar_list = that.data.my_calendar_list.my_subscribe_list;
        break;
      case 3:
        var calendar_list = that.data.my_calendar_list.my_joined_list;
        break;
    }
    that.setData({
      calendar_list: calendar_list,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})